
-- inverts the quotient after it comes out, if required.

--- combinatorial
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity quotient_handler is
	port(
	quotient_in : in STD_LOGIC_VECTOR(31 downto 0); -- for converting quotient
	
	is_signed : in STD_LOGIC;
	denominator_sign : in STD_LOGIC;
	numerator_sign : in STD_LOGIC;
	
	output : out STD_LOGIC_VECTOR(31 downto 0)
	
	
	);
end quotient_handler;

architecture Behavioral of quotient_handler is
begin
	process(quotient_in, is_signed, denominator_sign, numerator_sign)
		variable is_special_case : STD_LOGIC;
	begin
		is_special_case := numerator_sign and is_signed;
		if (is_special_case xor (is_signed and denominator_sign)) = '1' then
				-- flip quotient
			output <= STD_LOGIC_VECTOR(-signed(quotient_in));
		else
			output <= quotient_in;
		end if;
	
	end process;

end Behavioral;

